/*     */ package com.qmsk.business.store.goods.controller;
/*     */ 
/*     */ import com.qmsk.business.store.goods.dao.GoodsDAO;
/*     */ import com.qmsk.business.store.goodsbom.dao.GoodsBomDAO;
/*     */ import com.qmsk.business.store.goodsprice.dao.GoodsPriceDAO;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"goods"})
/*     */ public class GoodsController
/*     */ {
/*  34 */   private static final Logger logger = Logger.getLogger(GoodsController.class);
/*     */ 
/*     */   @Autowired
/*     */   private GoodsDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private GoodsPriceDAO goodsPriceDao;
/*     */ 
/*     */   @Autowired
/*     */   private GoodsBomDAO goodsBomDao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/barcode/{barcode}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOpt2ShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("barcode") String barcode, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  50 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try
/*     */     {
/*  53 */       Map params = new HashMap();
/*     */ 
/*  55 */       MapUtils.addToMap(params, "barcode", barcode);
/*  56 */       GsonEbRst rst = this.dao.getGsonOfAll(params, nPageIdx, nPageSize);
/*     */ 
/*  64 */       ResponseUtils.setResponseResult(rst, response);
/*     */     }
/*     */     catch (Exception e) {
/*  67 */       logger.error(e);
/*  68 */       ResponseUtils.setErrorMsgResponse(
/*  69 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/opt/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  79 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  81 */       Map params = new HashMap();
/*     */ 
/*  84 */       params.put("isWx", Integer.valueOf(1));
/*  85 */       params.put("typeMedID", 
/*  86 */         RequestUtils.getString(request, "goodsMedTypeId"));
/*  87 */       GsonEbRst gsonEbRst = this.dao.getGsonOfAll(params, nPageIdx, nPageSize);
/*  88 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/*  90 */       logger.error(e);
/*  91 */       ResponseUtils.setErrorMsgResponse(
/*  92 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/goodsId/{goodsId}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("goodsId") Long goodsId)
/*     */   {
/*     */     try {
/* 100 */       Map params = new HashMap();
/* 101 */       params.put("isWx", Integer.valueOf(1));
/* 102 */       params.put("goodsId", goodsId);
/* 103 */       GsonEbRst gsonEbRst = this.dao.getGoodsDetail(params);
/* 104 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/* 106 */       logger.error(e);
/* 107 */       ResponseUtils.setErrorMsgResponse(
/* 108 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/id/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListId(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id)
/*     */   {
/*     */     try {
/* 116 */       Map params = new HashMap();
/* 117 */       MapUtils.addToMap(params, "id", id);
/* 118 */       GsonEbRst gsonEbRst = this.dao.getGoodsDetail(params);
/* 119 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/* 121 */       logger.error(e);
/* 122 */       ResponseUtils.setErrorMsgResponse(
/* 123 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try
/*     */     {
/* 141 */       int nResult = 0;
/* 142 */       Long id = null;
/* 143 */       String sData = RequestUtils.getStringOfData(request);
/* 144 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 145 */       if ((p != null) && (p.isExistsInsertRows())) {
/* 146 */         for (int i = 0; i < p.getListInsertRows().size(); ++i) {
/* 147 */           GsonHeadOneRow g = (GsonHeadOneRow)p.getListInsertRows().get(i);
/* 148 */           String barCode = (String)g.getValueOfName("barCode");
/* 149 */           if (this.dao.getCheckBarCode(barCode).intValue() > 0) {
/* 150 */             ResponseUtils.setErrorMsgResponse("已有条码为" + barCode + 
/* 151 */               "的商品", response);
/* 152 */             return;
/*     */           }
/*     */         }
/*     */       }
/* 156 */       nResult = this.dao.applyUpdates(p, "id");
/* 157 */       if ((p.isExistsInsertRows()) && (nResult > 0)) {
/* 158 */         GsonHeadOneRow r = (GsonHeadOneRow)p.getListInsertRows().get(0);
/* 159 */         id = ObjectComm.objectToLong(r.getValueOfName("id"));
/*     */       }
/* 161 */       if ((nResult > 0) || (p == null) || (p.isExistsRows())) {
/* 162 */         ParserDataSetJson pgdsPrice = 
/* 163 */           ParserDataSetJson.fromString(RequestUtils.getString(request, 
/* 164 */           "goodsPrice"));
/* 165 */         if (pgdsPrice != null) {
/* 166 */           if (pgdsPrice.isExistsInsertRows()) {
/* 167 */             for (int i = 0; i < pgdsPrice.getListInsertRows()
/* 168 */               .size(); )
/*     */             {
/* 169 */               GsonHeadOneRow r = 
/* 170 */                 (GsonHeadOneRow)pgdsPrice.getListInsertRows()
/* 170 */                 .get(i);
/* 171 */               if (id != null)
/* 172 */                 r.autoAddHeadData("id", id);
/* 168 */               ++i;
/*     */             }
/*     */ 
/*     */           }
/*     */ 
/* 176 */           nResult += this.goodsPriceDao.applyUpdates(pgdsPrice);
/*     */         }
/*     */ 
/* 179 */         ParserDataSetJson pgdsBom = 
/* 180 */           ParserDataSetJson.fromString(RequestUtils.getString(request, "goodsBom"));
/* 181 */         if (pgdsBom != null) {
/* 182 */           if (pgdsBom.isExistsInsertRows()) {
/* 183 */             for (int i = 0; i < pgdsBom.getListInsertRows().size(); ++i) {
/* 184 */               GsonHeadOneRow r = (GsonHeadOneRow)pgdsBom.getListInsertRows().get(
/* 185 */                 i);
/* 186 */               if (id != null) {
/* 187 */                 r.autoAddHeadData("id", id);
/*     */               }
/*     */             }
/*     */           }
/* 191 */           nResult += this.goodsBomDao.applyUpdates(pgdsBom);
/*     */         }
/*     */       }
/* 194 */       if (nResult > 0)
/* 195 */         DbConnection.commit();
/*     */       else {
/* 197 */         DbConnection.rollback();
/*     */       }
/* 199 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 200 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 201 */         response);
/*     */     } catch (Exception e) {
/* 203 */       logger.error(e);
/* 204 */       DbConnection.rollback();
/* 205 */       ResponseUtils.setErrorMsgResponse(
/* 206 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 207 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void edit(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try
/*     */     {
/* 225 */       int nResult = 0;
/* 226 */       String sData = RequestUtils.getStringOfData(request);
/* 227 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 228 */       if (p != null) {
/* 229 */         if (p.isExistsUpdateRows()) {
/* 230 */           for (int i = 0; i < p.getListUpdateRows().size(); ++i) {
/* 231 */             GsonHeadOneRow g = (GsonHeadOneRow)p.getListUpdateRows().get(i);
/* 232 */             String barCode = (String)g.getValueOfName("barCode");
/* 233 */             if ((!(StringUtils.isNotEmpty(barCode))) || 
/* 234 */               (this.dao.getCheckBarCode(barCode).intValue() <= 0)) continue;
/* 235 */             ResponseUtils.setErrorMsgResponse("已有条码为" + 
/* 236 */               barCode + "的商品", response);
/* 237 */             return;
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 242 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/* 244 */       if ((nResult > 0) || (p == null)) {
/* 245 */         ParserDataSetJson pgdsPrice = 
/* 246 */           ParserDataSetJson.fromString(RequestUtils.getString(request, 
/* 247 */           "goodsPrice"));
/* 248 */         nResult += this.goodsPriceDao.applyUpdates(pgdsPrice);
/*     */ 
/* 250 */         ParserDataSetJson pgdsBom = 
/* 251 */           ParserDataSetJson.fromString(RequestUtils.getString(request, "goodsBom"));
/* 252 */         nResult += this.goodsBomDao.applyUpdates(pgdsBom);
/*     */       }
/* 254 */       if (nResult > 0)
/* 255 */         DbConnection.commit();
/*     */       else {
/* 257 */         DbConnection.rollback();
/*     */       }
/* 259 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 260 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 261 */         response);
/*     */     } catch (Exception e) {
/* 263 */       logger.error(e);
/* 264 */       DbConnection.rollback();
/* 265 */       ResponseUtils.setErrorMsgResponse(
/* 266 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 267 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 283 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 285 */       String[] strParams = id.split(",");
/* 286 */       int nResult = this.dao.deleteParams(strParams);
/* 287 */       nResult += this.goodsPriceDao.deleteParams(strParams);
/* 288 */       nResult += this.goodsBomDao.deleteParams(strParams);
/* 289 */       if (nResult > 0)
/* 290 */         DbConnection.commit();
/*     */       else {
/* 292 */         DbConnection.rollback();
/*     */       }
/* 294 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 295 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 296 */         response);
/*     */     } catch (Exception e) {
/* 298 */       DbConnection.rollback();
/* 299 */       logger.error(e);
/* 300 */       ResponseUtils.setErrorMsgResponse(
/* 301 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 302 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.goods.controller.GoodsController
 * JD-Core Version:    0.5.3
 */